import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import vueJsx from '@vitejs/plugin-vue-jsx';
import legacy from '@vitejs/plugin-legacy'
import VitePluginHtmlEnv from 'vite-plugin-html-env'
import { visualizer } from "rollup-plugin-visualizer";
import Icons from 'unplugin-icons/vite'
import IconsResolver from 'unplugin-icons/resolver'
import { VantResolver } from 'unplugin-vue-components/resolvers';
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue({
      script: {
        defineModel: true
      }
    }),
    vueJsx(),
    legacy(),
    VitePluginHtmlEnv(),
    visualizer({
      open: true,
      gzipSize: true,
      brotliSize: true,
    }),
    AutoImport({
      imports: ['vue', 'vue-router', 'pinia'],
      dts: './src/types/auto-import.d.ts',
      vueTemplate: true,
      resolvers: [
        IconsResolver(),

      ],
    }),
    Icons({
      autoInstall: true,
    }),
    Components({
      dts: './src/types/components.d.ts',
      resolvers: [
        IconsResolver(),
        VantResolver()
      ],
      dirs: ['src/components'], // 按需加载的文件夹
    })
  ],

  base: './',

  server: {
    port: 3000,
  },
  resolve: {
    alias: {
      '~': resolve(__dirname, 'src'),
      '#': resolve(__dirname, 'src/types'),
    }
  },
  build: {
    // outDir:'../backend/public/dist',
    chunkSizeWarningLimit: 2000,
    rollupOptions: {
      output: {
        manualChunks(id: string) {
          if (id.includes('node_modules')) {
            return id.toString().split('node_modules/')[1].split('/')[0].toString();
          }
        }
      }
    }
  },
})
